package com.liming.admin.service.impl;

import com.liming.admin.service.OrderService;
import com.liming.common.pojo.dto.order.admin.RefundPageQuery;
import com.liming.common.pojo.vo.PageVO;
import com.liming.common.pojo.vo.order.openfeign.FeignOrderDetailVO;
import com.liming.common.pojo.vo.order.openfeign.FeignOrderItemVO;
import com.liming.common.pojo.vo.order.web.OrderDetailVO;
import com.liming.common.pojo.vo.order.web.OrderItemVO;
import com.liming.common.pojo.vo.order.web.RefundOrderVO;
import com.liming.common.util.FeignBeanUtils;
import com.liming.order.client.AdminOrderClient;
import com.liming.order.client.AdminRefundOrderClient;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author liming
 * @date 2025/3/1
 */
@Service
@AllArgsConstructor
public class OrderServiceImpl implements OrderService {

    private final AdminOrderClient adminOrderClient;
    private final AdminRefundOrderClient adminRefundOrderClient;

    @Override
    public OrderDetailVO orderDetail(Long id) {
        FeignOrderDetailVO feignOrderDetailVO = adminOrderClient.orderDetail(id);
        List<FeignOrderItemVO> feignList = feignOrderDetailVO.getOrderItemList();
        OrderDetailVO result = FeignBeanUtils.toBean(feignOrderDetailVO, OrderDetailVO.class);
        result.setOrderItemList(FeignBeanUtils.toBean(feignList, OrderItemVO.class));
        return result;
    }

    @Override
    public PageVO<RefundOrderVO> refundPage(RefundPageQuery query) {
        return adminRefundOrderClient.refundPage(query);
    }

    @Override
    public Boolean agreeRefund(Long refundOrderId) {
        return adminRefundOrderClient.agreeRefund(refundOrderId);
    }

    @Override
    public Boolean refuseRefund(Long refundOrderId, String reason) {
        return adminRefundOrderClient.refuseRefund(refundOrderId, reason);
    }

    @Override
    public Boolean queryRefund(Long refundOrderId) {
        return adminRefundOrderClient.queryRefund(refundOrderId);
    }
}
